package com.maimao.user.controller;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.ExcelWriter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @author MaoLin Wang
 * @date 2021/4/5 11:29 上午
 */
@RestController
@RequestMapping("/test")
public class TestController {
    @Autowired
    private Environment environment;

    @GetMapping("/value")
    public String getValue(@RequestParam("key") String key) {
        String property = environment.getProperty(key);
        System.out.println(property);
        return environment.getProperty(key);
    }

    public static void main(String[] args) {
        Map<String, Object> row1 = new LinkedHashMap<>();
        row1.put("姓名", "张三");
        row1.put("年龄", 23);
        row1.put("成绩", 88.32);
        row1.put("是否合格", true);
        row1.put("考试日期", DateUtil.date());

        Map<String, Object> row3 = new LinkedHashMap<>();
        row3.put("姓名", "李四");
        row3.put("年龄", 33);
        row3.put("成绩", 59.50);
        row3.put("是否合格", false);
        row3.put("考试日期", DateUtil.date());

        Map<String, Object> row2 = new LinkedHashMap<>();
        row2.put("姓名", "张三");
        row2.put("年龄", 24);
        row2.put("成绩", 88.32);
        row2.put("是否合格", true);
        row2.put("考试日期", DateUtil.date());

        ArrayList<Map<String, Object>> rows = CollUtil.newArrayList(row1, row2,row3);
        // 通过工具类创建writer
        ExcelWriter writer = ExcelUtil.getWriter("/Users/wangmaolin/IdeaProjects/maimao/maimao_server/maimao_parent/maimao_user/src/main/resources/export/b.xlsx");
        writer.merge(rows.size() - 1, "test");
        writer.setRowHeight(2,2);
        writer.write(rows, true);
        writer.close();
    }
}
